//
//  PostsItemView.m
//  ;
//
//  Created by yinqy on 15/3/3.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "PostsItemView.h"
#import "TitleStyleView.h"
#import "PostsItemPicView.h"


@interface PostsItemView()
{
    TitleStyleView *_titleStyleView;
    UILabel *_titleLabel;
    UILabel *_descLabel;
    PostsItemPicView *_picView;
    UIButton *_authorBtn;
    UIButton *_replyCountBtn;
    UILabel *_replyTimeBtn;
}

@end

@implementation PostsItemView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _titleStyleView = [[TitleStyleView alloc]init];
        [self addSubview:_titleStyleView];
        
        _titleLabel = [[UILabel alloc]init];
        [_titleLabel setFont:TITLE_FONT];
        [_titleLabel setTextColor:JXColor(51, 51, 51)];
        [self addSubview:_titleLabel];
        
        _descLabel = [[UILabel alloc]init];
        [_descLabel setFont:DESC_FONT];
        [_descLabel setTextColor:JXColor(102, 102, 102)];
        [self addSubview:_descLabel];
        
        _picView = [[PostsItemPicView alloc]init];
        [self addSubview:_picView];
        
        _authorBtn = [[UIButton alloc]init];
        [_authorBtn setTitleColor:JXColor(153, 153, 153) forState:UIControlStateNormal];
        [_authorBtn.titleLabel setFont:AUTHOR_FONT];
        [_authorBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
        [self addSubview:_authorBtn];
        
        _replyCountBtn = [[UIButton alloc]init];
        [_replyCountBtn setTitleColor:JXThemeColor forState:UIControlStateNormal];
        [_replyCountBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
        [_replyCountBtn setImage:[UIImage imageNamed:@"replyNum_icon_heighlight"] forState:UIControlStateNormal];
        [_replyCountBtn.titleLabel setFont:AUTHOR_FONT];
        [self addSubview:_replyCountBtn];
        
        _replyTimeBtn = [[UILabel alloc]init];
        [_replyTimeBtn setFont:AUTHOR_FONT];
        [_replyTimeBtn setTextColor:JXColor(153, 153, 153)];
        [self addSubview:_replyTimeBtn];
        
    }
    return self;
}

-(void)setPostsFrame:(PostsItemFrame *)postsFrame{
    _postsFrame = postsFrame;
    [self setFrame:postsFrame.frame];
    
    _titleStyleView.frame = postsFrame.titleStyleFrame;
    [_titleStyleView setTitleStyles:postsFrame.posts.titleStyles];
    
    _titleLabel.frame = postsFrame.titleFrame;
    [_titleLabel setText:postsFrame.posts.title];
    
    _descLabel.frame = postsFrame.descFrame;
    [_descLabel setText:postsFrame.posts.content];
    
    
    _picView.frame = postsFrame.picViewFrame;
    [_picView setImages:postsFrame.posts.img];
    if (postsFrame.posts.img!=nil &&postsFrame.posts.img.count!=0) {
        [_picView setHidden:NO];
    }else{
        [_picView setHidden:YES];
    }
    
    NSString *genderImg = @"ic_gender_small_unknow";
    //判断是男是女
    if ([[NSString stringWithFormat:@"%@",postsFrame.posts.userGender] isEqualToString:@"1"]) {
        genderImg = @"ic_gender_small_man";
    }else if([[NSString stringWithFormat:@"%@",postsFrame.posts.userGender] isEqualToString:@"2"]){
        genderImg = @"ic_gender_small_woman";
    }
    //判断是否是vip
    if (postsFrame.posts.level) {
        genderImg = [NSString stringWithFormat:@"%@_vip",genderImg];
    }
    [_authorBtn setImage:[UIImage imageNamed:genderImg] forState:UIControlStateNormal];
    [_authorBtn setTitle:postsFrame.posts.nickName forState:UIControlStateNormal];
    [_authorBtn setFrame:postsFrame.authorFrame];
    
    [_replyCountBtn setTitle:[NSString stringWithFormat:@"%d",postsFrame.posts.replyNum] forState:UIControlStateNormal];
    _replyCountBtn.frame = postsFrame.replyCountFrame;
    
    [_replyTimeBtn setText:postsFrame.posts.replyTime];
    _replyTimeBtn.frame = postsFrame.replyTimeFrame;
    
}

@end
